<?php

namespace CNAM\ActimanBundle\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\Controller;

class ControlController extends Controller
{
    public function indexAction()
    {
        return $this->render('CNAMActimanBundle:Default:index.html.twig');
    }
    
    //Recherche d'un user
    public function menuResultAgent()
    {
        $em = $this->getDoctrine()->getManager();
        $repository_user = $em->getRepository('CNAMActimanBundle:User');
        $list_user = $repository_user->findAll();
        //$resultUser = $this->userRecherche($nomUser);
        return $this->render('CNAMActimanBundle:Control:menuResultAgent.html.twig',array('list_user' => $list_user));
    }
    
    public function menuRechercherServiceAction()
    {
        $em = $this->getDoctrine()->getManager();
        
        $repository_service = $em->getRepository('CNAMActimanBundle:Service');
        $list_service = $repository_service->findAll(); 
        
        $repository_user = $em->getRepository('CNAMActimanBundle:User');
        $list_user = $repository_user->findAll();
        
        $repository_tache = $em->getRepository('CNAMActimanBundle:Tache');
        $list_tache = $repository_tache->findAll();

        return $this->render('CNAMActimanBundle:Control:menuRechercherService.html.twig', array('list_service' => $list_service, 'list_user' => $list_user, 'list_tache' => $list_tache));
    }
    
    //renvoie liste des agents
    public function menuRechercherAgentAction()
    {
        $em = $this->getDoctrine()->getManager();
        
        $repository_tache = $em->getRepository('CNAMActimanBundle:Tache'); 
        $list_tache = $repository_tache->findBy(Array(),Array('User'=>'DESC'));
       
        return $this->render('CNAMActimanBundle:Control:menuRechercherAgent.html.twig',array('list_tache' => $list_tache));
    }
    
    public function menuVisualiserAgentAction($idtache,$iduser)
    {
        $em = $this->getDoctrine()->getManager();
        
        $repository_tache = $em->getRepository('CNAMActimanBundle:Tache');
        $tached = $repository_tache->find($idtache);
        $list_tache = $repository_tache->findBy(Array('User' => $iduser),Array('nomTache' => 'DESC'));
        
        return $this->render('CNAMActimanBundle:Control:menuVisualiserAgent.html.twig',array('tached' => $tached, 'list_tache' => $list_tache));
    }
    
     public function menuRechercherProcAction()
    {
        $em = $this->getDoctrine()->getManager();
        
        $repository_procedureplanifiee = $em->getRepository('CNAMActimanBundle:ProcedurePlanifiee'); 
        $list_procedureplanifiee = $repository_procedureplanifiee->findAll();
        
        return $this->render('CNAMActimanBundle:Control:menuRechercherProc.html.twig',array('list_procedureplanifiee' => $list_procedureplanifiee));
    }
    
    public function menuVisualiserProcAction($idproc)
    {
        $em = $this->getDoctrine()->getManager();
        
        $repository_procedureplanifiee = $em->getRepository('CNAMActimanBundle:ProcedurePlanifiee');
        $proc = $repository_procedureplanifiee->find($idproc);
        
        $repository_phaseplanifiee = $em->getRepository('CNAMActimanBundle:phasePlanifiee');
        $list_phase = $repository_phaseplanifiee->findBy(Array('ProcedurePlanifiee' => $idproc));
        
        $repository_tache = $em->getRepository('CNAMActimanBundle:Tache');
        $tabResult = array();
        $tabResult = null;
        $ligne = 0;
        foreach ($list_phase as $phase) {
            $tabResult[$ligne] = $phase;
            $ligne = $ligne + 1;
        }
        $list_tache = $repository_tache->findBy(Array('phasePlanifiee' => $tabResult));
        
        return $this->render('CNAMActimanBundle:Control:menuVisualiserProc.html.twig',array('proc' => $proc, 'list_phase' => $list_phase, 'list_tache' => $list_tache));
    }
    
}
